<template>
  <div class="queryCheck-container">
    <div class="title">报告查询</div>
    <div class="detail">
      <van-form @submit="onSubmit">
      <van-field
        v-model="checkno"
        name="检查号"
        label="检查号"
        placeholder="输入检查号"
        size="15px"
        :rules="[{ required: true, message: '请填写检查号' }]"
      />

       <van-field
            readonly
            clickable
            name="checkdata"
            :value="checkdate"
            label="检查年份"
            placeholder="请选择检查年份"
            @click="()=>{checkdate1 = true;addWorkInfo={type:'time_getfirst',index:0}}"
            :rules="[{ required: true, message: '请选择检查年份' }]"
        />

    <div style="margin: 16px;">
      <van-button round block type="info" native-type="submit">查询</van-button>
    </div>
  </van-form>
    </div>

<!-- date-picker  van-datetime-picker -->
      <van-popup v-model="checkdate1" position="bottom">
          <van-datetime-picker
              v-model="currentDate"              
              @confirm="setVanDate" 
              @cancel="checkdate1=false"
              type="date"
            
              title="选择年份"
          />

          <!-- <el-date-picker v-model="currentDate" type="year"  columns-type="year" value-format="yyyy"> -->
<!-- </el-date-picker> -->
      </van-popup>

  </div>
</template>
<script>
import { Form, Field, Toast, NavBar, Button,  Popup, picker, DatetimePicker,ActionSheet } from "vant";
import _ from "lodash";
export default {
  name: "queryCheck",
  components: {
    [Form.name]: Form,
    [Button.name]: Button,
    [Field.name]: Field,
    [Popup.name]: Popup,
    [picker.name]: picker,
    [DatetimePicker.name]: DatetimePicker,
    [ActionSheet.name]: ActionSheet,
  },
  data() {
    return {
      checkno: "",
      zid:'',
      hoscode:'',
      checkdate:'',
      checkdate1: false,
      addWorkInfo:{type:'start',index:0},
      currentDate:new Date(),
      detail:''

    };
  },
  mounted() {
    // querchekk 给公众号使用，无特殊需求的公共查询 ；自助 无日期筛选 先复制页面吧 后面在说 240206
    this.hoscode = this.$route.query.hoscode || 0;
    this.checkno = this.$route.query.checkno || "";
    this.checkdate=this.$route.query.checkdate || "";
    //checkdate:new Date(),
    if(this.checkdate==""){
       let nowdate=this.timeChange(this.currentDate)
       let noedatearr=nowdate.split('-')
       this.checkdate=noedatearr[0];
    }
     console.log("fgfdgfd",this.hoscode,"当前："+ this.checkdate ); 

  },
  methods: {
   formatter(type, value) {
            if (type === 'year') {
                return '';
            } else if (type === 'month' || type === 'day' || type === 'hour' || type === 'minute') {
                return value;
            }
        }, 
    setVanDate(e){
        //this.formDtata.validTo = this.$d(e).format("YYYY-MM-DD")
        // console.log(e);
        // console.log('this.addWorkInfo',this.addWorkInfo);
        //  if(this.addWorkInfo.type == "start"){
        //   this.workjli[this.addWorkInfo.index].startDate=dayjs(e).format('YYYY-MM-DD');
        // }else if(this.addWorkInfo.type == 'end'){
        //    this.workjli[this.addWorkInfo.index].endDate=dayjs(e).format('YYYY-MM-DD');
        // }else if(this.addWorkInfo.type == 'timest_worktz'){
        //   this.timest_worktz=dayjs(e).format('YYYY-MM-DD');
        // }else if(this.addWorkInfo.type == 'timeed_worktz'){
        //   this.timeed_worktz=dayjs(e).format('YYYY-MM-DD');
        // }else if(this.addWorkInfo.type == 'time_getfirst'){
        //     this.formValidate.time_getfirst=dayjs(e).format('YYYY-MM-DD');
        // }
        //  this.checkdate=dayjs(e).format('YYYY-MM-DD');
          let nowdate=this.timeChange(e);
          let noedatearr=nowdate.split('-')
         this.checkdate=noedatearr[0];
 
         this.checkdate1=false;
      },

      timeChange(e) {
            var that = this
            var date = new Date(e);
            var y = date.getFullYear(); // 年
            var m = date.getMonth() + 1; // 月
            m = m < 10 ? ('0' + m) : m;
            var d = date.getDate(); // 日
            d = d < 10 ? ('0' + d) : d;
            var h = date.getHours(); // 时
            h = h < 10 ? ('0' + h) : h;
            var min = date.getMinutes(); // 分
            min = min < 10 ? ('0' + min) : min;
            var s = date.getSeconds(); // 秒
            s = s < 10 ? ('0' + s) : s;
               //let timere = y + '-' + m + '-' + d + 'T' + h + ':' + min + ':' + s;//拼在一起
                 let timere = y + '-' + m + '-' + d;//拼在一起
              return timere; 
             }, 

           timeChangearr(e) {
            var that = this
            var date = new Date(e);
            var y = date.getFullYear(); // 年
            var m = date.getMonth() + 1; // 月
            m = m < 10 ? ('0' + m) : m;
            var d = date.getDate(); // 日
            d = d < 10 ? ('0' + d) : d;
            var h = date.getHours(); // 时
            h = h < 10 ? ('0' + h) : h;
            var min = date.getMinutes(); // 分
            min = min < 10 ? ('0' + min) : min;
            var s = date.getSeconds(); // 秒
            s = s < 10 ? ('0' + s) : s;
               //let timere = y + '-' + m + '-' + d + 'T' + h + ':' + min + ':' + s;//拼在一起
                 let timere = y + '-' + m + '-' + d;//拼在一起

              return timere; 
             }, 


    gotoDetail() {
           // let urltz="/mobile/checking?zid=".intval($this.zid)."&token=".TOKENAPI."&totime=".TOKENNOWTIME;
            // $linshitz.="&hoscode=".$res['hospitalid'];	
      //  this.$router.push({path:'/mobile/checkingzzj',query:{zid:this.zid,
      //   checkno: this.checkno,hoscode: this.hoscode,checkdate:this.checkdate}});
        if(this.detail.noneedcheckname || this.hoscode==194){
            // talb 姓名英文。
          this.$router.push({path:'/mobile/checkingzzjnocheck',query:{zid:this.zid,
          checkno: this.checkno,hoscode: this.hoscode,checkdate:this.checkdate}});
        }else{
          this.$router.push({path:'/mobile/checkingzzj',query:{zid:this.zid,
        checkno: this.checkno,hoscode: this.hoscode,checkdate:this.checkdate}});
        }
      //this.$router.push("/mobile/checking",{zid:this.zid,checkno:this.checkno,hoscode:this.hoscode});
    },
    onSubmit() {
      Toast.loading({ message: "加载中...", forbidClick: true });
      if(this.hoscode==""){
        return Toast.fail("确实医院编码");
      } 

      if(this.checkdate==""){
        return Toast.fail("请选择检查日期");
      } 
 
      const reg = /^\s*$/
      if (reg.test(this.checkno) || this.checkno=="" ) {         
        return Toast.fail("请输入检查号");
      }
      let serchercheckdate=this.checkdate+"-01-01"
 
      this.$http
        .get(this.$API.QUERY_CHECK_SEARCHv2, {
          checkNo: this.checkno,
          hospitalId: this.hoscode,
          checkdate:serchercheckdate
        })
        .then((res) => {
          Toast.clear();
          if (res.code == 200) {
            this.zid=res.data.id;
            this.detail=res.data;
            console.log("res",this.detail);
            this.gotoDetail()
          } else {
            return Toast.fail(res.msg);
          }
        });
    }
  },
};
</script>
<style lang="less" scoped>
.queryCheck-container {
  padding:25% 15px 0 15px;
  .title{
    font-size: 28px;
    color:#333;
    font-weight: bold;
    text-align: center;
  }
  .detail{
    padding:10px;
    background: #fff;
    border-radius: 8px;
    margin-top:40px;
  }
}
::v-deep .van-field__control::placeholder{
  font-size: 18px;
}

::v-deep .van-cell{
  font-size: 18px;
}


</style>


